<!DOCTYPE html>
<html>
<head>
<title>添加栏目</title>
[#include "/WEB-INF/admin/include/common.html"]
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>添加栏目</h5>
            </div>
           <form id="inputForm" action="save" method="post">
	            <div class="ibox-content">
	                <div class="form-horizontal clearfix">
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label">名称：</label>
	                        <div class="col-sm-3">
	                            <input placeholder="名称" class="form-control" type="text" name="name">
	                        </div>
	                    </div>
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label">目录：</label>
	                        <div class="col-sm-3">
	                            <input placeholder="目录" class="form-control" type="text" name="directory">
	                        </div>
	                    </div>
	                     <div class="form-group">
	                        <label class="col-sm-3 control-label">上级分类：</label>
	                        <div class="col-sm-3">
	                            <select class="form-control" name="parentId">
									<option value="">顶级分类</option>
									[#list categoryTree as categoryItem]
										<option value="${categoryItem.id}">
											[#if categoryItem.grade != 0]
												[#list 1..categoryItem.grade as i]
													&nbsp;&nbsp;
												[/#list]
											[/#if]
											${categoryItem.name}
										</option>
									[/#list]
								</select>
	                        </div>
	                    </div>
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label">类型：</label>
	                        <div class="col-sm-3">
	                            <div class="radio" id="type">
	                            	 [#list categoryTypeNames.keyList() as key]
		                               <label class="m-r"><input name="type" value="${key}" type="radio">${categoryTypeNames.get(key)}</label>
	                            	[/#list]
	                            </div>
	                        </div>
	                    </div>
                    </div>
                    <div class="form-horizontal clearfix" id="listType" style="display: none">
                    	<div class="form-group">
	                        <label class="col-sm-3 control-label">模型：</label>
	                        <div class="col-sm-3">
	                            <select class="form-control" name="contentModelId" id="contentModelId">
									[#list contentModels as contentModel]
										<option value="${contentModel.id}">${contentModel.name}</option>
									[/#list]
								</select>
	                        </div>
	                    </div>
                    	<div class="form-group">
	                        <label class="col-sm-3 control-label">列表模板：</label>
	                        <div class="col-sm-3">
	                            <input placeholder="列表模板" class="form-control" type="text" name="listTemplate" id="listTemplate">
	                        </div>
	                    </div>
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label"> 列表显示数量：</label>
	                        <div class="col-sm-3">
	                        	<input placeholder="列表显示数量" class="form-control" type="text" name="listPageSize">
	                        </div>
                        </div>
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label">内容模板：</label>
	                        <div class="col-sm-3">
	                            <input placeholder="内容模板" class="form-control" type="text" name="contentTemplate" id="contentTemplate">
	                        </div>
	                    </div>
                    </div>
                    <div class="form-horizontal clearfix" id="pageType" style="display: none">
                    	<div class="form-group">
	                        <label class="col-sm-3 control-label">页面模板：</label>
	                        <div class="col-sm-3">
	                            <input placeholder="页面模板" class="form-control" type="text" name="pageTemplate">
	                        </div>
	                    </div>
                    	<div class="form-group">
	                        <label class="col-sm-3 control-label">页面内容：</label>
	                        <div class="col-sm-8">
	                           <textarea id="pageContent" name="pageContent" class="ibox-content no-padding" style="height: 250px;"></textarea>
	                        </div>
	                    </div>
                    </div>
                    <div class="form-horizontal clearfix" id="linkType" style="display: none">
                    	<div class="form-group">
	                        <label class="col-sm-3 control-label">链接地址：</label>
	                        <div class="col-sm-3">
	                            <input placeholder="链接地址" class="form-control" type="text" name="linkUrl">
	                        </div>
	                    </div>
                    </div>
                    <div class="form-horizontal clearfix">
                    	<div class="form-group">
	                        <label class="col-sm-3 control-label">图片：</label>
	                        <div class="col-sm-3">
	                            <input type="text" name="image" class="form-control" />
	                        </div>
	                        <div class="col-sm-3">
								<a href="javascript:;" id="filePicker" class="btn btn-primary">选择文件</a>
	                        </div>
	                    </div>
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label">标题：</label>
	                        <div class="col-sm-3">
	                            <input placeholder="标题" class="form-control" type="text" name="title">
	                        </div>
	                    </div>
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label">关键词：</label>
	                        <div class="col-sm-3">
	                            <input placeholder="关键词" class="form-control" type="text" name="keywords">
	                        </div>
	                    </div>
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label">描述：</label>
	                        <div class="col-sm-3">
	                            <input placeholder="描述" class="form-control" type="text" name="description">
	                        </div>
	                    </div>
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label">排序：</label>
	                        <div class="col-sm-3">
	                            <input placeholder="排序" class="form-control" type="text" name="sort">
	                        </div>
	                    </div>
	                    <div class="form-group">
	                        <label class="col-sm-3 control-label">设置：</label>
	                        <div class="col-sm-3">
	                            <div class="checkbox">
	                            	<label class="m-r"><input type="checkbox" name="isMenu" value="true">做为菜单</label>
	                               <label class="m-r"><input type="checkbox" name="isEnabled" value="true" checked/>启用</label>
	                            </div>
	                        </div>
	                    </div>
	                </div>
	            </div>
	            <div class="modal-footer col-sm-3 col-sm-offset-2">
	                <button type="submit" class="btn btn-w-m btn-primary">确定</button>
	                <button type="button" class="btn btn-w-m btn-default" onclick="history.back(); return false;">取消</button>
	            </div>
            </form>
        </div>
    </div>
</body>
</html>
<script type="text/javascript">
function loadTemplate(){
	var contentModelId = $("#contentModelId").val();
	$.ajax({
        url: "modelTemplate",
        type: "POST",
        data: {"contentModelId":contentModelId},
        dataType: "json",
        cache: false,
        success: function(data) {
            $("#listTemplate").val(data.listTemplate);
            $("#contentTemplate").val(data.contentTemplate);
        }
    });
}
loadTemplate();

$().ready(function() {

	var $inputForm = $("#inputForm");
	var $type = $("#type");
	var $contentModelId = $("#contentModelId");
	var $pageContent = $("#pageContent");
	var $filePicker = $("#filePicker");
	
	$filePicker.uploader();
	
	$pageContent.editor();
	
	$type.on("click","input[type='radio']",function(){
		$("#listType").hide();
		$("#pageType").hide();
		$("#linkType").hide();
		$("#"+$(this).val()+"Type").show();
	});
	
   $contentModelId.change(function() {
	   loadTemplate();
    });
	
	
	// 表单验证
	$inputForm.validate({
		rules: {
			name: "required",
			sort: "digits",
			isEnabled: "required"
		}
	});

});
</script>
